<%@ page contentType="text/html; charset=utf-8" language="java" pageEncoding="UTF-8" %>
<%@ include file="/common.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
	
    <link rel="stylesheet" href="/css/style_ie_1.0.css" type="text/css">
    
    <script src="/js/prototype.js" type="text/javascript" language="javascript"></script>	
	<script src="/js/share.js" type="text/javascript" language="javascript"></script>
	<script src="/js/main.js" type="text/javascript" language="javascript"></script>
	<title>Blue_Dream--&gt;我的信箱</title>
</head>
  
<body>
	<jsp:include page="/frame/header.jsp" flush="true" />
	<div id="main" class="main">
		<%
			boolean isNew = session.isNew();
			UserType user = (UserType)session.getAttribute("user");
			if (isNew || (!isNew && null == user)){
				out.println("<div align='center'><b>您还没有登陆，想查阅您的信箱，请先登陆！</b></div>");
			}else {
				Collection emails = EmailQuery.queryNotReadEmailsByUser(dreamDB, user);
				if (emails.isEmpty())
					out.print("<div>您没有任何未读留言</div>");
				else {
					out.print("<div>您有如下未读留言：</div>");
					out.print("<table border='1'>");
					out.print("<tr><td nowrap>序号</td><td nowrap>标题</td><td>内容</td><td nowrap>发送人</td><td nowrap>发送时间</td></tr>");
				}
				Iterator iter = emails.iterator();
				int loopCnt = 0;
				while (iter.hasNext()) {
					EmailType email = (EmailType)iter.next();
					UserType sendUser = email.getSendUser();
					out.print("<tr><td>" + (++loopCnt) + "</td><td nowrap>" + email.getTitle() + "</td><td>" + email.getContent() + "</td><td>" + sendUser.getName() + "</td><td nowrap>" + DateTool.getFormatDate("yyyy-MM-dd HH:mm:ss", email.getSendTime()) +  "</td></tr>");
				}
				out.print("</table>");
				
				Collection readedEmails = EmailQuery.queryReadedEmailsByUser(dreamDB, user);
				if (readedEmails.isEmpty())
					out.print("<div>您没有任何已读留言</div>");
				else {
					out.print("<div>您有如下已读留言：</div>");
					out.print("<table border='1'>");
					out.print("<tr><td nowrap>序号</td><td nowrap>标题</td><td>内容</td><td nowrap>发送人</td><td nowrap>发送时间</td></tr>");
				}
				Iterator iter2 = readedEmails.iterator();
				loopCnt = 0;
				while (iter2.hasNext()) {
					EmailType email = (EmailType)iter2.next();
					UserType sendUser = email.getSendUser();
					out.print("<tr><td>" + (++loopCnt) + "</td><td nowrap>" + email.getTitle() + "</td><td>" + email.getContent() + "</td><td>" + sendUser.getName() + "</td><td nowrap>" + DateTool.getFormatDate("yyyy-MM-dd HH:mm:ss", email.getSendTime()) +  "</td></tr>");
				}
				out.print("</table>");
		%>
				<p ><br /><br /><br /><span>撰写新的留言：</span></p>
				<div id="sendmsgframe" class="">
					<form id="" method="get" action="/ajaxapi/ajaxapi.jsp" onsubmit="sendMail(this, kindEditor);return false;"><%--不要忘了return false;--%>
						<div style="display:block;float:left">发送到：</div><input type="text" name="mailto" maxLength="200" size="80" width="686" /> <br />
						<div style="display:block;float:left">标　题：</div><input type="text" name="mailtitle" maxLength="45" size="80" width="686" /> <br />
						<div style="display:block;float:left">正　文：</div><div style="width:668px;height:400px;"><iframe src="/frame/editor.html" scrolling="no" frameborder="0" border="0" width="668px" height="550px"></iframe></div><br />
						<!-- <div style="display:block;float:left">正　文：</div><div style="width:668px;height:400px;float:block;">
							<input type="hidden" name="mailcontent" value="请在此输入邮件内容" />
							<script type="text/javascript" language="javascript" src="/editor/kindeditor-2.4/KindEditor.js"></script>
							<script type="text/javascript" language="javascript">
								var kindEditor = new KindEditor("kindEditor");
								kindEditor.hiddenName = "mailcontent";
								kindEditor.siteDomain = "test.blue-dream.com";
								kindEditor.skinPath = "/editor/kindeditor-2.4/skins/tiny/";
								kindEditor.iconPath = "/editor/kindeditor-2.4/icons/";
								kindEditor.imageAttachPath = "/editor/kindeditor-2.4/attached/";
								kindEditor.editorWidth = "668px";
								kindEditor.editorHeight = "400px";
								kindEditor.menuBorderColor = '#CCCCCC';
								kindEditor.menuBgColor = '#F0F0EE';
								kindEditor.menuTextColor = '#222222';
								kindEditor.menuSelectedColor = '#CCCCCC';
								kindEditor.toolbarBorderColor = '#CCCCCC';
								kindEditor.toolbarBgColor = '#F0F0EE';
								kindEditor.formBorderColor = '#CCCCCC';
								kindEditor.buttonColor = '#DDDDDD';
								kindEditor.show();

							</script>
						</div><br /> -->
						<div align="right" style="margin-right: 46px;"><input type="reset" value="重 写" style="margin-right:8px;" /><input type="submit" name="submitmail" value="发 送" style="margin-left:8px;"/></div>
					</form>
				</div>
				
		<%	}	%>
	</div>
    
    <jsp:include page="/frame/footer.jsp" flush="true" />
    <jsp:include page="/frame/login.jsp" flush="true" />
</body>
</html>
